package com.bayleaf.web.stringMatching;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;

import com.bayleaf.core.BayleafServlet;
import com.bayleaf.core.Model;
import com.bayleaf.dao.BayleafDictionaryDAO;
import com.bayleaf.domain.DictionaryVO;
import com.bayleaf.web.stringMatching.dao.StringMatchingDAO;

@WebServlet(name="makeName",
            urlPatterns={"/makeName"},
            initParams={ @WebInitParam(name="title", value="MakeName"), @WebInitParam(name="jsp", value="/makeName/MakeName") } )
public class MakeNameServlet extends BayleafServlet {

	public String process(Model model) throws Exception {

		System.out.println(model.getString("names"));
		
		List<DictionaryVO> matchedNameArray = new ArrayList<DictionaryVO>();

		
		BayleafDictionaryDAO dao = new BayleafDictionaryDAO();

		if ("init".equals(model.getString("names"))) {
				List<DictionaryVO> list = dao.getStdNameListAll();
				
				List<String> al_ko_first = new ArrayList<String>();
				List<String> al_en_first = new ArrayList<String>();
				for(DictionaryVO vo: list){
					al_ko_first.add(vo.getStdName() + ":" +vo.getStdNameEng());  
					al_en_first.add(vo.getStdNameEng() + ":" +vo.getStdName());  
				}
				model.setObject("matchedNameEn", al_en_first.toArray());
				model.setObject("matchedNameKo", al_ko_first.toArray());
				
				return null;
		}else	if ("on".equals(model.getString("findId"))) {
			matchedNameArray = dao.getStdNameListByNm(model.getString("names"),
					"EN");
		} else if ("on".equals(model.getString("findName"))) {
			matchedNameArray = dao.getStdNameListByNm(model.getString("names"),
					"KO");
		} else {
			matchedNameArray = dao.getStdNameListByNm(model.getString("names"),
					"");
		}

		model.setObject("matchedName", matchedNameArray.toArray());
		return null;
	}

}
